# -*- coding: utf-8 -*-
# -----------------------------------------
# @Time       : 2018/6/18 13:53
# @Author     : dqz 
# @Email      : 1406990390@qq.com
# @File       : api.py
# @Software   : PyCharm
# -----------------------------------------
import json

from flask import Blueprint, request, jsonify


diff = Blueprint("diff", __name__, url_prefix="/db/diff")
from .func import diff_sql


@diff.route("/table", methods=("POST",))
def diff_table():
    params = json.loads(request.get_data(as_text=True))
    infos = {
        "status": False,
        "msg": ""
    }
    try:
        src = params["src"]
        dest = params["dest"]
        return_type = params.get("return_type", 1)
        infos = diff_sql(src, dest, return_type)
    except Exception as e:
        infos["msg"] = "src or dest is needed!"

    return jsonify(infos)
